﻿using Alos;
using Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Alos
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Common.RequestAdministratorPrivileges((args) =>
            {
                Run();
            }, new string[] { });
        }

        static void Run()
        {
            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            if (Environment.UserInteractive)
            {
                FormMain f = new FormMain();
                f.ShowDialog();
                return;
            }
            Application.EnableVisualStyles();
            // 作为服务启动
            ServiceBase.Run(new ServiceBase[] { new AlosService() });
        }

        private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            Log.errorlog(new Exception("应用程序发生异常:" + e.Exception.Message));
        }
    }
}
